﻿using System.Runtime.Serialization;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;

namespace MusicWorks.Service.DataContracts
{
    [DataContract(Namespace = "http://schemas.microsoft.com/Search/2008/suggestions")]
    public class SearchSuggestion
    {
        [DataMember(EmitDefaultValue = false)]
        public string Url { get; set; }

        [DataMember]
        public string Text { get; set; }

        [DataMember(EmitDefaultValue = false)]
        public string Description { get; set; }

        [DataMember(Name = "Image", EmitDefaultValue = false)]
        public SearchSuggestionImage Image { get; set; }
    }
    public class SearchSuggestionImage : IXmlSerializable
    {
        public string Source { get; set; }
        public string Alt { get; set; }
        public int Height { get; set; }
        public int Width { get; set; }
        public XmlSchema GetSchema()
        {
            return null;
        }
        public void ReadXml(XmlReader reader)
        {
            //we never actually load our results from XML
        }
        public void WriteXml(XmlWriter writer)
        {
            writer.WriteAttributeString("source", Source);
            writer.WriteAttributeString("alt", Alt);
            if (string.IsNullOrEmpty(Height.ToString()) == false)
                writer.WriteAttributeString("height", Height.ToString());
            if (string.IsNullOrEmpty(Width.ToString()) == false)
                writer.WriteAttributeString("width", Width.ToString());
        }
    }
}
